// pages/home-page/home-page.js
var postData = require('../../data/data.js')
var dateTimePicker = require('../../data/dateTime.js');
var base = require('../../conf.js')
Page({
  data: {
    temp: {
      sellerId: 0,
      info: '',
      phone: '11111',
      people: '',
      time: null,
      code: ''
    },
    area: ['北京', '广州', '上海', '深圳'],
    dateTime: null,
    dateTimeArray: null,
    dateTimeArray1: null,
    dateTime1: null,
    canClick: false,
    time: '',
    disabled: false,
    currentTime: 60
  },
  calling: function (e) {
    wx.makePhoneCall({
      phoneNumber: e.currentTarget.dataset.replyPhone
    })
  },
  bindPickerChange: function (e) {
    this.setData({
      areaIndex: e.detail.value
    })
  },
  onLoad: function (options) {
    // 获取完整的年月日 时分秒，以及默认显示的数组
    var obj = dateTimePicker.dateTimePicker(this.data.startYear, this.data.endYear);
    var obj1 = dateTimePicker.dateTimePicker(this.data.startYear, this.data.endYear);
    // 精确到分的处理，将数组的秒去掉
    var lastArray = obj1.dateTimeArray.pop();
    var lastTime = obj1.dateTime.pop();
    this.setData({
      ktv_key: postData.ktvlist,
      act_key: postData.actlist,
      
      dateTime: obj.dateTime,
      dateTimeArray: obj.dateTimeArray,
      dateTimeArray1: obj1.dateTimeArray,
      dateTime1: obj1.dateTime
    });
    this.getSellerName()
  },
  getSellerName: function () {
    var self = this;
    wx.request({
      url: base.url + '/sellerName',
      method: 'get',
      header: {
        "Content-Type": "application/json;charset=UTF-8",
        'userToken': base.token_Date
      },
      success: function (res) {
        console.log(res.data.data)
        var sellerMsg = res.data.data
        var area=[]
        for (var i = 0; i < sellerMsg.length; ++i){
          area.push(sellerMsg[i].name)
        }
        self.setData({
          area: area
        })
      }
    })
  },
  onKtvdetailTap: function (event) {
    var postid = event.currentTarget.dataset.postid;
    console.log("KTV页第" + postid + "被点击了");
    wx.navigateTo({
      url: "/pages/topic/index"
    })
  },
  toOrder: function () {
    wx.navigateTo({
      url: "/pages/home-page/order"
    })
  },
  changeDateTime(e) {
    this.setData({ dateTime: e.detail.value });
  },
  changeDateTime1(e) {
    this.setData({ dateTime1: e.detail.value });
  },
  changeDateTimeColumn(e) {
    var arr = this.data.dateTime, dateArr = this.data.dateTimeArray;
    arr[e.detail.column] = e.detail.value;
    dateArr[2] = dateTimePicker.getMonthDay(dateArr[0][arr[0]], dateArr[1][arr[1]]);
    this.setData({
      dateTimeArray: dateArr,
      dateTime: arr
    });
  },
  changeDateTimeColumn1(e) {
    var arr = this.data.dateTime1, dateArr = this.data.dateTimeArray1;
    arr[e.detail.column] = e.detail.value;
    dateArr[2] = dateTimePicker.getMonthDay(dateArr[0][arr[0]], dateArr[1][arr[1]]);
    this.setData({
      dateTimeArray1: dateArr,
      dateTime1: arr
    });
  },
  disDate: function () {
    if (!this.isDisable) {
      this.isDisable = 'disabled'
    } else {
      this.isDisable = false
    }
  },
  getUserCode: function () {
    /*
    let phone = this.temp.phone
    let isPhone = /^1[34578]\d{9}$/
    if (isPhone.test(phone)) {
      let me = this
      me.canClick = true
      let interval = window.setInterval(function () {
        if ((me.time--) <= 0) {
          me.time = 60
          me.canClick = false
          window.clearInterval(interval)
        }
      }, 1000)
      this.disabled = false
      let params = { "phone": this.temp.phone }
      getCode(params).then(res => {
        this.userCode = res.data
      }).catch(error => {
        console.log(error)
      })
    }
    else {
      alert("您的号码格式不正确或不合法输入！请重新输入：")
    }
    */
  },
  Yzm: function () {
    var that = this;

    that.setData({
      canClick: (!that.data.canClick),
    })
    var currentTime = that.data.currentTime;
    interval = setInterval(function () {
      currentTime--;
      that.setData({
        time: currentTime + '秒后重新发送'
      })
      if (currentTime <= 0) {
        clearInterval(interval)
        that.setData({
          //time: '重新发送',
          currentTime: 61,
          canClick: (!that.data.canClick),
        })
      }
    }, 1000)
  }
})